import java.util.*;
import java.io.*;
class Read {
    StringTokenizer st = new StringTokenizer("");
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    String next() throws IOException {
        while(!st.hasMoreTokens()) {
            st = new StringTokenizer(bf.readLine());
        }
        return st.nextToken();
    }
    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
}
public class code2{

    public static Read in = new Read();
    public static int n;
    public static int[][] arr;

    public static void Row() {
        //arr[i][j]与arr[n-1-i][j]交换
        for(int i=0;i<n/2;i++) {
            for(int j=0;j<n;j++) {
                int tmp = arr[i][j];
                arr[i][j] = arr[n-1-i][j];
                arr[n-1-i][j] = tmp;
            }
        }
    }

    public static void Col() {
        //arr[i][j]与arr[i][n-1-j]交换
        for(int j=0;j<n/2;j++) {
            for(int i=0;i<n;i++) {
                int tmp = arr[i][j];
                arr[i][j] = arr[i][n-1-j];
                arr[i][n-1-j] = tmp;
            }
        }
    }
    public static void main(String[] args) throws IOException{
        n = in.nextInt();
        arr = new int[n][n];
        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++) {
                arr[i][j] = in.nextInt();
            }
        }
        int q = in.nextInt();
        int row =0,col =0;
        while(q--!=0) {
            int x = in.nextInt();
            if(x==1) {
                row++;col++;
            }else {
                row++;
            }
        }
        row%=2;col%=2;
        if(row!=0) Row();
        if(col!=0) Col();

        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++) {
                System.out.print(arr[i][j]+" ");
            }
            System.out.println();
        }

    }

}